package com.wcy.controller.user;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wcy.entity.UserFeedback;
import com.wcy.entity.UserLearningHistory;
import com.wcy.entity.pageVo.ApiDescriptor;
import com.wcy.entity.pageVo.ColumnConstructor;
import com.wcy.entity.pageVo.PageData;
import com.wcy.feign.resource.FeignLearningResourceService;
import com.wcy.feign.user.FeignUserLearningHistoryService;
import com.wcy.service.FeignService;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
public class UserLearningHistoryController {
    @Resource
    private FeignUserLearningHistoryService feignUserLearningHistoryService;
    @GetMapping("userLearningHistory/page")
    public ResponseEntity<PageData<UserLearningHistory>> getPage(@RequestParam(name = "pageNum",defaultValue = "1") int pageNum,
                                                                 @RequestParam(name = "pageSize",defaultValue = "10") int pageSize) {
        return ResponseEntity.ok(new PageData<>(UserLearningHistory.class, Objects.requireNonNull(feignUserLearningHistoryService.getPage(pageNum, pageSize).getBody()),  new ApiDescriptor("userLearningHistory/add", "userLearningHistory/update", "userLearningHistory/delete"), ColumnConstructor.create()));
    }
    @GetMapping("userLearningHistory/list")
    public ResponseEntity<List<UserLearningHistory>> getList() {
        return feignUserLearningHistoryService.getList();
    }
    @PostMapping("userLearningHistory/add")
    public ResponseEntity<Void> add(@RequestBody UserLearningHistory userLearningHistory) {
        return feignUserLearningHistoryService.add(userLearningHistory);
    }
    @PutMapping("userLearningHistory/update")
    public ResponseEntity<Void> update(@RequestBody UserLearningHistory userLearningHistory) {
        return feignUserLearningHistoryService.update(userLearningHistory);
    }
    @DeleteMapping("userLearningHistory/delete/{id}")
    public ResponseEntity<Void> delete(@PathVariable("id") Integer id) {
        return feignUserLearningHistoryService.delete(id);
    }

    @PostMapping("userLearningHistory/sendHistory")
    public ResponseEntity<Void> sendHistory(@RequestBody UserLearningHistory userLearningHistory){
        return feignUserLearningHistoryService.sendHistory(userLearningHistory);
    }

    @GetMapping("userLearningHistory/user/getHistoryData")
    public ResponseEntity<List<UserLearningHistory>> getHistoryData(){
        return feignUserLearningHistoryService.getHistoryData();
    }

    @GetMapping("userLearningHistory/user/page")
    public ResponseEntity<PageData<UserLearningHistory>> getUserHistoryPage(@RequestParam(name = "pageNum",defaultValue = "1") int pageNum,
                                                                        @RequestParam(name = "pageSize",defaultValue = "10") int pageSize){
        return ResponseEntity.ok(new PageData<>(UserLearningHistory.class, Objects.requireNonNull(feignUserLearningHistoryService.getUserHistoryPage(pageNum, pageSize).getBody()),  new ApiDescriptor("", "", "userLearningHistory/user/delete"), ColumnConstructor.create()).setAlias("删除记录",""));
    }

    @DeleteMapping("userLearningHistory/user/delete/{id}")
    public ResponseEntity<Void> deleteHistory(@PathVariable("id") Integer id) {
        return feignUserLearningHistoryService.deleteHistory(id);
    }

    @GetMapping("userLearningHistory/user/sum")
    public ResponseEntity<Long> getSumLearningTime(){
        return feignUserLearningHistoryService.getSumLearningTime();
    }
//    @GetMapping("userLearningHistory/user/history")
//    public ResponseEntity<Void>
}
